#include "pressure.h"

Pressure::Pressure(QWidget *parent) : QMainWindow(parent)
{
    this->setStyleSheet("QMainWindow{background-image: url(:/pic/背景板.png);}");
    this->setFixedSize(640,430);
ui_init();
ui_Btn_Init();
connect_init();
}
void Pressure::connect_init()
{
    //确定
    connect(theBtn[0],&QPushButton::clicked,[=](){

        });
    connect(theBtn[1],&QPushButton::clicked,[=](){
        this->parentWidget()->show();
        this->close();
        });
}

void Pressure::ui_init()
{
    for(int i=0;i<5;i++)//创建界面显示的label
    {
         theLabel[i] = new QLabel(this);
         theLabel[i]->setStyleSheet("QLabel{\
                                outline: 0px ;                            /* 去掉获取焦点时的虚线 */ \
                                background-color: rgb(255, 20, 55);	    /* 背景颜色 */\
                                border-radius: 6px;		                 /* 按钮边框的圆角设置 */\
                                border-style: outset;\
                                /* 按钮文本设置 */\
                                qproperty-alignment: 'AlignCenter| AlignCenter';			             /* 文本的位置 */\
                                font-size: 20px;\
                                color: #abcccc;			                 /* 文本颜色 */\
                           }"
          );
    }

    theLabel[0]->setStyleSheet("QLabel{"
                          + the_StyleSheet[20]+ " font-size: 25px;"+ "background-color: rgb(20, 70, 255);	    /* 背景颜色 */"+  "}"    );
    theLabel[1]->setStyleSheet("QLabel{ image: url(:/pic/左.png); }"    );
    theLabel[2]->setStyleSheet("QLabel{ image: url(:/pic/右.png); }"    );

   theLabel[0]->setGeometry(0,0,640,60);//设定每隔放置一个按键
   theLabel[1]->setGeometry(0,0,300,60);//设定每隔放置一个按键
   theLabel[2]->setGeometry(340,0,300,60);//设定每隔放置一个按键
   theLabel[0]->setText("版本信息");

   theLabel[3]->setGeometry(50,100,200,40);//设定每隔放置一个按键
   theLabel[3]->setText("压力");
   theLabel[4]->setGeometry(350,100,200,40);//设定每隔放置一个按键
   theLabel[4]->setText(QString::number(Sysstatus->Air_Pressure,'f',2)+"     Kpa");

   }

    void Pressure::ui_Btn_Init()
    {
        for(int i=0;i<2;i++)//创建主屏幕显示的按键
        {

             theBtn[i] = new QPushButton(this);
    //        newbutton->setGeometry(30+(i*150),260,120,90 );//设定每隔放置一个按键
            theBtn[i]->geometry();
    }

        theBtn[0]->setStyleSheet(  "QPushButton{"+the_StyleSheet[0]+ "background-image: url(:/pic/.png); /* 背景图片 */"+"}"
         "QPushButton:focus{"+the_StyleSheet[1]+ "background-image: url(:/pic/2.png); /* 背景图片 */"+"}");
        theBtn[1]->setStyleSheet(  "QPushButton{"+the_StyleSheet[0]+ "border-radius:4px;  border: 1px groove white; padding:1px 4px; border-style: outset;"+ "background-image: url(:/pic/回.png); /* 背景图片 */"+"}"
         "QPushButton:focus{"+the_StyleSheet[1]+ "background-image: url(:/pic/返2.png); /* 背景图片 */"+"}");

    theBtn[0]->setGeometry(50,130,90,50 );
    theBtn[0]->setText(tr("确定"));
    theBtn[0]->installEventFilter(this);
    theBtn[1]->setGeometry(240,300,160,50 );
    theBtn[1]->setText(tr("返回"));
    theBtn[1]->installEventFilter(this);
   theBtn[0]->hide();
    }

    bool Pressure::eventFilter(QObject *watched, QEvent *event)
    {
        if(theBtn[0] == watched||theBtn[1] == watched)
    {
        if(event->type() == QEvent::KeyPress)
        {
            QKeyEvent *ev = (QKeyEvent *)event;
            QPushButton *button = (QPushButton *)watched;

           {
               switch (ev->key())
               {
               case LEFT://左
               {
                      focusPreviousChild();
                 break;
               }
               case RIGHT://右
               {
                      focusNextChild();
              break;
               }
               case OK:
               {
                   emit  button-> clicked();
                 break;
               }
               case BACK:
               {
                   this->parentWidget()->show();
                   this->close();
                   break;
               }
               case INIT:
               {
                   init_Show *show = new init_Show(this);
                   show->show();
                   this->hide();

                   break;
               }
                default:
                   break;
               }
           }
        }
        }
        return QWidget::eventFilter(watched,event);//返回父类的事件过滤器

    }
